package com.zhuhjay.common.base.model.domain;

import com.zhuhjay.common.base.util.MailSenderUtils;
import lombok.Data;

/**
 * 邮件模板参数
 *
 * @author ZhuHJay
 * @date 2023/8/8 17:05
 */
@Data
public class MailTemplate {

    /**
     * 邮件收件人
     */
    private String to;
    /**
     * 邮件主题/操作主题
     */
    private String subject;
    /**
     * 邮件所需地址(邮箱绑定/解绑/重置链接等)
     */
    private String href;
    /**
     * 前端地址
     */
    private String frontUrl;

    public static MailTemplate of(String to, MailSenderUtils.MailSubject subject, String frontUrl, String route) {
        MailTemplate mailTemplate = new MailTemplate();
        mailTemplate.setTo(to);
        mailTemplate.setSubject(subject.getSubject());
        mailTemplate.setFrontUrl(frontUrl);
        mailTemplate.setHref(frontUrl + route);
        return mailTemplate;
    }

    public void parseHref(String code) {
        this.href = this.href.replace("{email}", this.to).replace("{code}", code);
    }

}
